using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Evaluant.Uss;
using Evaluant.Uss.ObjectContext;

namespace TestUSS
{
	[TestClass]
	public class TestPrevalence : Common
	{
		protected override void CreatePersistenceEngine()
		{
			pef = XmlConfigLoader.LoadXmlConfig("engines.config", "Prevalence");
		}

		[TestMethod]
		public void MemoryUsage()
		{
			ObjectService factory = new ObjectService("engines.config", "Xml");
			ObjectContext pm = factory.CreateObjectContext();
			factory.AddAssembly("NUnit");

			Counter c = new Counter();

			double memory1, memory2;

			memory1 = Environment.WorkingSet / 1024;

			int MAX = 50000;
			int POINT = 20;

			Console.WriteLine("{0}\t{1}\t{2}", "items", "memory", "time");

			pm.BeginTransaction();

			c.Start();
			for(int i=1; i<=MAX; i++)
			{
				MyNamespace.Person p = new MyNamespace.Person();
				p.FirstName = "Jesus";
				p.Title = MyNamespace.Title.Sir;
				p.Friends.Add(p);

				pm.Serialize(p);

				// Gets a  points results 
				if(i % (MAX / POINT) == 0)
				{
					memory2 = Environment.WorkingSet / 1024;
					Console.WriteLine("{0}\t{1}\t{2}", i, memory2 - memory1, c.Elapsed().TotalSeconds);
				}
			}

			Console.WriteLine("Committing");
			pm.CommitTransaction();
			Console.WriteLine(c.Elapsed().TotalSeconds);

//			Console.WriteLine("Statistical repartition of elements in the HasdhedDictionnary");
//			foreach(int i in Evaluant.Uss.Common.HashedDictionnary._Repartition)
//				Console.WriteLine(i );
		}

		[TestMethod]
		public void Debug()
		{
			LoadReference();			
		}

	}
}
